package org.hwadee.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.hwadee.entity.Category;
import org.hwadee.entity.Post;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CategoryMapper {

//    @Select("select * from category")
//    List<Category> getAllCategories();

    @Select("select * from category where categoryStatus = 1 and categoryName != #{str}")
    List<Category> getAllCategories(String str);

    @Insert("insert into category(categoryName, description) values (#{categoryName}, #{description})")
    void insertCategory(Category category);

    @Update("update category set categoryStatus = 0 where categoryId = #{categoryId}")
    void deleteCategory(Category category);

    @Select("select * from category where categoryId = #{id}")
    Category getCategoryById(Integer id);

    @Select("select category from post where postId = #{id} and postStatus = 1")
    Integer getCategoryIdByPostId(Integer postId);

    @Update("update category set categoryName = #{categoryName}, description = #{description} where categoryId = #{categoryId}")
    void updateCategory(Category category);

    @Select("select * from category where categoryName = #{str}")
    Post getCategoryByCategoryName(String str);

    @Select("select * from category where categoryStatus = 1 and categoryName = #{str}")
    Category getNotice(String str);
}
